<template>
  <div class="video">
    <video-player  class="video-player-box"
      ref="videoPlayer"
      :options="playerOptions"
      :playsinline="true"
      customEventName="customstatechangedeventname"
      @play="onPlayerPlay($event)"
      @pause="onPlayerPause($event)"
      @ended="onPlayerEnded($event)"
      @waiting="onPlayerWaiting($event)"
      @playing="onPlayerPlaying($event)"
      @loadeddata="onPlayerLoadeddata($event)"
      @timeupdate="onPlayerTimeupdate($event)"
      @canplay="onPlayerCanplay($event)"
      @canplaythrough="onPlayerCanplaythrough($event)"

      @statechanged="playerStateChanged($event)"
      @ready="playerReadied">
    </video-player>
  </div>
</template>

<script>
import 'video.js/dist/video-js.css';
import { videoPlayer } from 'vue-video-player';
export default {
  name: 'video',
  components: {
    videoPlayer
  },
  props: {
    playerOptions: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {};
  },
  computed: {
    player() {
      return this.$refs.videoPlayer.player;
    }
  },
  created() {
    // this.getSmsList();
  },
  methods: {
    // listen event
    onPlayerPlay($event) {
      this.$emit('onPlayerPlay', $event);
    },
    onPlayerPause($event) {
      this.$emit('onPlayerPause', $event);
    },
    // or listen state event
    playerStateChanged(playerCurrentState) {
      // console.log('player current update state', playerCurrentState)
    },
    //媒体的readyState为HAVE_FUTURE_DATA或更高
    onPlayerCanplay(player) {
      // console.log('player Canplay!', player)
    },
    //媒体的readyState为HAVE_ENOUGH_DATA或更高。这意味着可以在不缓冲的情况下播放整个媒体文件。
    onPlayerCanplaythrough(player) {
      // console.log('player Canplaythrough!', player)
    },
    // 当播放器在当前播放位置下载数据时触发
    onPlayerLoadeddata($event) {
      console.log($event);
    },
    // DOM元素上的readyState更改导致播放停止
    onPlayerWaiting($event) {},
    // player is ready
    playerReadied($event) {
      console.log('the player is readied', $event);
    },
    // 当前播放位置发生变化时触发。
    onPlayerTimeupdate($event) {},
    // 已开始播放回调
    onPlayerPlaying($event) {
      console.log($event);
    }
  }
};
</script>

<style scoped lang="less">
.video {
  /deep/ .vjs-big-play-button {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  /deep/ .video-js .vjs-control-bar {
    background-color: #000;
    padding: 6px 0;
    height: 43px;
  }
  /deep/ .video-js .vjs-big-play-button {
    width: 1.5em;
    height: 1.5em;
    border-radius: 100px;
    line-height: 1.4em;
  }
  /deep/ .video-js .vjs-play-progress:before {
    top: -0.4em;
  }
}
</style>
